<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 200px;
        height: 200px;
        background: #ccc;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button @click="change">toggle</button>
      <div class="box" v-show="flag"></div>

      <hr />
      <ul>
        <li v-for="(item,index) in arr">
          姓名：{{item.name}}年龄：{{item.age}}
          <span @click="remove(index)">x</span>
        </li>
      </ul>
    </div>
    <script src="vue-2.4.0.js"></script>
    <script>
      var vm = new Vue({
        el: "#app",
        data: {
          flag: true,
          arr: [
            { name: "杀崔猛", age: 29 },
            { name: "小红", age: 20 },
            { name: "小绿", age: 18 },
          ],
        },
        methods: {
          change() {
            this.flag = !this.flag;
          },
          remove(i) {
            this.arr.splice(i, 1);
          },
          //删除数组中的某一项 ，第一个参数是从哪儿开始删，第二个参数是删除几个
        },
      });
    </script>
  </body>
</html>
